/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.forms.phthang;

import com.aptech.beans.Orders;
import com.aptech.dao.CustomerManager;
import com.aptech.dao.DrugManager;

import com.aptech.dao.OrderManager;
import com.aptech.utility.DBType;
import com.aptech.utility.DBUtil;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.PreparedStatement;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.ImageIcon;

/**
 *
 * @author Huu Thang
 */
public class OrdersList extends javax.swing.JFrame {

    DefaultTableModel tableModel;

    /**
     * Creates new form NewJFrame
     */
    public OrdersList() {
        initComponents();
        setLocationRelativeTo(null);
        loadOrder();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Jdialog_InsertUpdate = new javax.swing.JDialog();
        pnCustomerInfo = new javax.swing.JPanel();
        lbCustomerName = new javax.swing.JLabel();
        lbEmail = new javax.swing.JLabel();
        lbAddress = new javax.swing.JLabel();
        lbPhone = new javax.swing.JLabel();
        lbRelation = new javax.swing.JLabel();
        txtRelationYesNo = new javax.swing.JLabel();
        btnChooseCustomer = new javax.swing.JButton();
        txtCustomerName = new javax.swing.JLabel();
        txtEmail = new javax.swing.JLabel();
        txtAddress = new javax.swing.JLabel();
        txtPhone = new javax.swing.JLabel();
        lbCustomerID = new javax.swing.JLabel();
        txtCustomerID = new javax.swing.JLabel();
        pnDrugs = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtbDrugs = new javax.swing.JTable();
        pbDrugsList = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtbDrugslist = new javax.swing.JTable();
        btnSaveOrder = new javax.swing.JButton();
        btnExit = new javax.swing.JButton();
        btnAddtoOrder = new javax.swing.JButton();
        btnRemove = new javax.swing.JButton();
        lbQuantity = new javax.swing.JLabel();
        txtQuantity = new javax.swing.JTextField();
        lbTotal = new javax.swing.JLabel();
        txtTotal = new javax.swing.JLabel();
        txtDiscount = new javax.swing.JLabel();
        JDialog_ChooseCustomer = new javax.swing.JDialog();
        jScrollPane4 = new javax.swing.JScrollPane();
        tbCustomerList = new javax.swing.JTable();
        btnChoose = new javax.swing.JButton();
        Jdialog_Update = new javax.swing.JDialog();
        pnCustomerInfo1 = new javax.swing.JPanel();
        lbCustomerName1 = new javax.swing.JLabel();
        lbEmail1 = new javax.swing.JLabel();
        lbAddress1 = new javax.swing.JLabel();
        lbPhone1 = new javax.swing.JLabel();
        lbRelation1 = new javax.swing.JLabel();
        txtRelationYesNo1 = new javax.swing.JLabel();
        txtCustomerName1 = new javax.swing.JLabel();
        txtEmail1 = new javax.swing.JLabel();
        txtAddress1 = new javax.swing.JLabel();
        txtPhone1 = new javax.swing.JLabel();
        lbCustomerID1 = new javax.swing.JLabel();
        txtCustomerID1 = new javax.swing.JLabel();
        pnDrugs1 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jtbDrugs1 = new javax.swing.JTable();
        lbTotal1 = new javax.swing.JLabel();
        txtTotal1 = new javax.swing.JLabel();
        txtDiscount1 = new javax.swing.JLabel();
        lbQuantity1 = new javax.swing.JLabel();
        txtQuantity1 = new javax.swing.JTextField();
        btnSaveQuantity = new javax.swing.JButton();
        btnRemovedrug = new javax.swing.JButton();
        btnSaveUpdateOrder = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        lbOrderID = new javax.swing.JLabel();
        txtOrderID = new javax.swing.JLabel();
        cbRole = new javax.swing.JComboBox();
        jlblAccList_Email1 = new javax.swing.JLabel();
        lbOrderManager = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableOrderList = new javax.swing.JTable();
        btnDelete = new javax.swing.JButton();
        btnInsert = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();

        Jdialog_InsertUpdate.setTitle("Order detail");
        Jdialog_InsertUpdate.setResizable(false);

        pnCustomerInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Customer Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 0, 51))); // NOI18N

        lbCustomerName.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbCustomerName.setText("Customer name:");

        lbEmail.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbEmail.setText("Email:");

        lbAddress.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbAddress.setText("Address:");

        lbPhone.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbPhone.setText("Phone:");

        lbRelation.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbRelation.setText("Have relationship?");

        btnChooseCustomer.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnChooseCustomer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/020.png"))); // NOI18N
        btnChooseCustomer.setText("Choose a customer");
        btnChooseCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChooseCustomerActionPerformed(evt);
            }
        });

        lbCustomerID.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbCustomerID.setText("Customer ID:");

        javax.swing.GroupLayout pnCustomerInfoLayout = new javax.swing.GroupLayout(pnCustomerInfo);
        pnCustomerInfo.setLayout(pnCustomerInfoLayout);
        pnCustomerInfoLayout.setHorizontalGroup(
            pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnCustomerInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnCustomerInfoLayout.createSequentialGroup()
                        .addComponent(lbRelation)
                        .addGap(18, 18, 18)
                        .addComponent(txtRelationYesNo, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnCustomerInfoLayout.createSequentialGroup()
                        .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(lbEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lbCustomerName, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))
                            .addComponent(lbPhone)
                            .addComponent(lbAddress)
                            .addComponent(lbCustomerID))
                        .addGap(25, 25, 25)
                        .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                            .addComponent(btnChooseCustomer)
                            .addComponent(txtCustomerName, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                            .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                            .addComponent(txtCustomerID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(36, Short.MAX_VALUE))
        );
        pnCustomerInfoLayout.setVerticalGroup(
            pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnCustomerInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCustomerID)
                    .addComponent(txtCustomerID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCustomerName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmail)
                    .addComponent(lbEmail))
                .addGap(18, 18, 18)
                .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbAddress, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtAddress, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtPhone, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbPhone, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnCustomerInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnCustomerInfoLayout.createSequentialGroup()
                        .addComponent(lbRelation)
                        .addGap(132, 132, 132))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnCustomerInfoLayout.createSequentialGroup()
                        .addComponent(txtRelationYesNo)
                        .addGap(18, 18, 18)
                        .addComponent(btnChooseCustomer, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(63, 63, 63))))
        );

        pnDrugs.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Drugs", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 51, 102))); // NOI18N

        jtbDrugs.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Drug ID", "Drug name", "Unit Price", "Quantity", "Total Price"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbDrugs.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(jtbDrugs);
        if (jtbDrugs.getColumnModel().getColumnCount() > 0) {
            jtbDrugs.getColumnModel().getColumn(0).setResizable(false);
        }

        javax.swing.GroupLayout pnDrugsLayout = new javax.swing.GroupLayout(pnDrugs);
        pnDrugs.setLayout(pnDrugsLayout);
        pnDrugsLayout.setHorizontalGroup(
            pnDrugsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDrugsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnDrugsLayout.setVerticalGroup(
            pnDrugsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDrugsLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addContainerGap())
        );

        pbDrugsList.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Drugs List", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 51, 51))); // NOI18N

        jtbDrugslist.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Drug ID", "Drug Name", "Unit", "Unit Price", "Stock Available", "Description"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(jtbDrugslist);

        javax.swing.GroupLayout pbDrugsListLayout = new javax.swing.GroupLayout(pbDrugsList);
        pbDrugsList.setLayout(pbDrugsListLayout);
        pbDrugsListLayout.setHorizontalGroup(
            pbDrugsListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pbDrugsListLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3)
                .addContainerGap())
        );
        pbDrugsListLayout.setVerticalGroup(
            pbDrugsListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pbDrugsListLayout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                .addContainerGap())
        );

        btnSaveOrder.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnSaveOrder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/032.png"))); // NOI18N
        btnSaveOrder.setText("Save");
        btnSaveOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveOrderActionPerformed(evt);
            }
        });

        btnExit.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/033.png"))); // NOI18N
        btnExit.setText("Exit");
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });

        btnAddtoOrder.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnAddtoOrder.setText("Add");
        btnAddtoOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddtoOrderActionPerformed(evt);
            }
        });

        btnRemove.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnRemove.setText("Remove");
        btnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveActionPerformed(evt);
            }
        });

        lbQuantity.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbQuantity.setText("Quantity:");

        txtQuantity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtQuantityActionPerformed(evt);
            }
        });

        lbTotal.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbTotal.setText("Total Price:");

        txtTotal.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtTotal.setForeground(new java.awt.Color(255, 51, 51));
        txtTotal.setText("0.0");

        javax.swing.GroupLayout Jdialog_InsertUpdateLayout = new javax.swing.GroupLayout(Jdialog_InsertUpdate.getContentPane());
        Jdialog_InsertUpdate.getContentPane().setLayout(Jdialog_InsertUpdateLayout);
        Jdialog_InsertUpdateLayout.setHorizontalGroup(
            Jdialog_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Jdialog_InsertUpdateLayout.createSequentialGroup()
                .addGap(269, 269, 269)
                .addComponent(btnSaveOrder)
                .addGap(43, 43, 43)
                .addComponent(btnExit)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(Jdialog_InsertUpdateLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Jdialog_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Jdialog_InsertUpdateLayout.createSequentialGroup()
                        .addGroup(Jdialog_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(Jdialog_InsertUpdateLayout.createSequentialGroup()
                                .addComponent(lbTotal)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtDiscount)
                                .addGap(161, 161, 161))
                            .addGroup(Jdialog_InsertUpdateLayout.createSequentialGroup()
                                .addComponent(pnCustomerInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGroup(Jdialog_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(pnDrugs, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(Jdialog_InsertUpdateLayout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(lbQuantity)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                                .addComponent(btnAddtoOrder)
                                .addGap(33, 33, 33)
                                .addComponent(btnRemove, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(52, 52, 52))))
                    .addComponent(pbDrugsList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(23, 23, 23))
        );
        Jdialog_InsertUpdateLayout.setVerticalGroup(
            Jdialog_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Jdialog_InsertUpdateLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(Jdialog_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnCustomerInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnDrugs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(Jdialog_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnRemove)
                    .addComponent(lbQuantity)
                    .addComponent(txtQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbTotal)
                    .addComponent(txtTotal)
                    .addComponent(txtDiscount)
                    .addComponent(btnAddtoOrder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(pbDrugsList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addGroup(Jdialog_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnExit)
                    .addComponent(btnSaveOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        JDialog_ChooseCustomer.setTitle("Choose a customer");
        JDialog_ChooseCustomer.setResizable(false);

        tbCustomerList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Customer ID", "Customer Name", "Phone", "Email", "Address", "Have relationship?"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(tbCustomerList);

        btnChoose.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnChoose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/050.png"))); // NOI18N
        btnChoose.setText("Choose");
        btnChoose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChooseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout JDialog_ChooseCustomerLayout = new javax.swing.GroupLayout(JDialog_ChooseCustomer.getContentPane());
        JDialog_ChooseCustomer.getContentPane().setLayout(JDialog_ChooseCustomerLayout);
        JDialog_ChooseCustomerLayout.setHorizontalGroup(
            JDialog_ChooseCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JDialog_ChooseCustomerLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(JDialog_ChooseCustomerLayout.createSequentialGroup()
                .addGap(241, 241, 241)
                .addComponent(btnChoose)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        JDialog_ChooseCustomerLayout.setVerticalGroup(
            JDialog_ChooseCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JDialog_ChooseCustomerLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnChoose)
                .addContainerGap())
        );

        Jdialog_Update.setTitle("Update Order Information");

        pnCustomerInfo1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Customer Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 0, 51))); // NOI18N

        lbCustomerName1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbCustomerName1.setText("Customer name:");

        lbEmail1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbEmail1.setText("Email:");

        lbAddress1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbAddress1.setText("Address:");

        lbPhone1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbPhone1.setText("Phone:");

        lbRelation1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbRelation1.setText("Have relationship?");

        lbCustomerID1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbCustomerID1.setText("Customer ID:");

        javax.swing.GroupLayout pnCustomerInfo1Layout = new javax.swing.GroupLayout(pnCustomerInfo1);
        pnCustomerInfo1.setLayout(pnCustomerInfo1Layout);
        pnCustomerInfo1Layout.setHorizontalGroup(
            pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnCustomerInfo1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbRelation1)
                    .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnCustomerInfo1Layout.createSequentialGroup()
                            .addComponent(lbAddress1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 74, Short.MAX_VALUE)
                            .addComponent(txtAddress1, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnCustomerInfo1Layout.createSequentialGroup()
                            .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(lbEmail1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(lbCustomerName1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))
                                .addComponent(lbPhone1)
                                .addComponent(lbCustomerID1))
                            .addGap(25, 25, 25)
                            .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtCustomerName1, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                                .addComponent(txtEmail1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtRelationYesNo1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtCustomerID1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtPhone1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnCustomerInfo1Layout.setVerticalGroup(
            pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnCustomerInfo1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCustomerID1)
                    .addComponent(txtCustomerID1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCustomerName1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCustomerName1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtEmail1)
                    .addComponent(lbEmail1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbAddress1)
                    .addComponent(txtAddress1))
                .addGap(14, 14, 14)
                .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbPhone1)
                    .addComponent(txtPhone1))
                .addGap(11, 11, 11)
                .addGroup(pnCustomerInfo1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbRelation1)
                    .addComponent(txtRelationYesNo1))
                .addGap(90, 90, 90))
        );

        pnDrugs1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Drugs", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 51, 102))); // NOI18N

        jtbDrugs1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Drug ID", "Drug name", "Unit Price", "Quantity", "Total Price"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbDrugs1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbDrugs1MouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(jtbDrugs1);
        if (jtbDrugs1.getColumnModel().getColumnCount() > 0) {
            jtbDrugs1.getColumnModel().getColumn(0).setResizable(false);
        }

        javax.swing.GroupLayout pnDrugs1Layout = new javax.swing.GroupLayout(pnDrugs1);
        pnDrugs1.setLayout(pnDrugs1Layout);
        pnDrugs1Layout.setHorizontalGroup(
            pnDrugs1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDrugs1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnDrugs1Layout.setVerticalGroup(
            pnDrugs1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
        );

        lbTotal1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbTotal1.setText("Total Price:");

        txtTotal1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtTotal1.setForeground(new java.awt.Color(255, 51, 51));
        txtTotal1.setText("0.0");

        txtDiscount1.setText("discount");

        lbQuantity1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbQuantity1.setText("Quantity:");

        txtQuantity1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtQuantity1ActionPerformed(evt);
            }
        });

        btnSaveQuantity.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/051.png"))); // NOI18N
        btnSaveQuantity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveQuantityActionPerformed(evt);
            }
        });

        btnRemovedrug.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnRemovedrug.setText("Remove");
        btnRemovedrug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemovedrugActionPerformed(evt);
            }
        });

        btnSaveUpdateOrder.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnSaveUpdateOrder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/032.png"))); // NOI18N
        btnSaveUpdateOrder.setText("Save");
        btnSaveUpdateOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveUpdateOrderActionPerformed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/033.png"))); // NOI18N
        jButton4.setText("Exit");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        lbOrderID.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbOrderID.setText("Order ID:");

        cbRole.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        cbRole.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "COMPLETED", "UNCOMPLE" }));

        jlblAccList_Email1.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblAccList_Email1.setForeground(new java.awt.Color(51, 0, 255));
        jlblAccList_Email1.setText("Status");

        javax.swing.GroupLayout Jdialog_UpdateLayout = new javax.swing.GroupLayout(Jdialog_Update.getContentPane());
        Jdialog_Update.getContentPane().setLayout(Jdialog_UpdateLayout);
        Jdialog_UpdateLayout.setHorizontalGroup(
            Jdialog_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Jdialog_UpdateLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Jdialog_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Jdialog_UpdateLayout.createSequentialGroup()
                        .addComponent(lbTotal1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtTotal1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txtDiscount1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbOrderID)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtOrderID, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lbQuantity1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtQuantity1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSaveQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(45, 45, 45)
                        .addComponent(btnRemovedrug)
                        .addGap(28, 28, 28))
                    .addGroup(Jdialog_UpdateLayout.createSequentialGroup()
                        .addComponent(pnCustomerInfo1, javax.swing.GroupLayout.PREFERRED_SIZE, 385, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(pnDrugs1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 14, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Jdialog_UpdateLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jlblAccList_Email1)
                        .addGap(35, 35, 35)
                        .addComponent(cbRole, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(62, 62, 62)
                        .addComponent(btnSaveUpdateOrder)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4)
                        .addGap(195, 195, 195))))
        );
        Jdialog_UpdateLayout.setVerticalGroup(
            Jdialog_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Jdialog_UpdateLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Jdialog_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnDrugs1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(Jdialog_UpdateLayout.createSequentialGroup()
                        .addComponent(pnCustomerInfo1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, Short.MAX_VALUE)
                        .addGap(6, 6, 6)))
                .addGap(9, 9, 9)
                .addGroup(Jdialog_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbTotal1)
                    .addComponent(txtTotal1)
                    .addComponent(txtDiscount1)
                    .addComponent(lbQuantity1)
                    .addComponent(txtQuantity1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSaveQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRemovedrug)
                    .addComponent(lbOrderID)
                    .addComponent(txtOrderID))
                .addGap(40, 40, 40)
                .addGroup(Jdialog_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cbRole, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblAccList_Email1)
                    .addComponent(btnSaveUpdateOrder)
                    .addComponent(jButton4))
                .addGap(26, 26, 26))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Order Management");
        setIconImage(new ImageIcon(getClass().getResource("/com/image/icon.png")).getImage());

        lbOrderManager.setFont(new java.awt.Font("Segoe UI Light", 1, 24)); // NOI18N
        lbOrderManager.setForeground(new java.awt.Color(255, 0, 0));
        lbOrderManager.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbOrderManager.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/038.png"))); // NOI18N
        lbOrderManager.setText("Orders Management");
        lbOrderManager.setMaximumSize(new java.awt.Dimension(263, 64));
        lbOrderManager.setMinimumSize(new java.awt.Dimension(263, 64));
        lbOrderManager.setPreferredSize(new java.awt.Dimension(263, 64));

        tableOrderList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Order ID", "Customer", "Order date", "Ship date", "Total", "Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableOrderList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(tableOrderList);

        btnDelete.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/028.png"))); // NOI18N
        btnDelete.setText("Delete");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnInsert.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnInsert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/026.png"))); // NOI18N
        btnInsert.setText("Insert");
        btnInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInsertActionPerformed(evt);
            }
        });

        btnUpdate.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        btnUpdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/027.png"))); // NOI18N
        btnUpdate.setText("Update");
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 109, Short.MAX_VALUE)
                        .addComponent(btnInsert)
                        .addGap(57, 57, 57)
                        .addComponent(btnUpdate)
                        .addGap(43, 43, 43)
                        .addComponent(btnDelete)
                        .addGap(146, 146, 146))))
            .addGroup(layout.createSequentialGroup()
                .addGap(183, 183, 183)
                .addComponent(lbOrderManager, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbOrderManager, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDelete)
                    .addComponent(btnUpdate)
                    .addComponent(btnInsert))
                .addGap(23, 23, 23))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        //Delete an order.
        if (tableOrderList.getSelectedRowCount() == 1) {
            int reply = JOptionPane.showConfirmDialog(null, "Do you want to delete this order?", "Message",
                    JOptionPane.INFORMATION_MESSAGE);
            if (reply == JOptionPane.YES_OPTION) {
                try {
                    ResultSet resultSet = OrderManager.displayAllRows();
                    resultSet.absolute(tableOrderList.getSelectedRow() + 1);
                    resultSet.deleteRow();
                    loadOrder();
                } catch (SQLException ex) {
                    System.out.println(ex.toString());
                }
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please choose an order to delete!", "Message", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertActionPerformed

        Jdialog_InsertUpdate.setVisible(true);
        Jdialog_InsertUpdate.setLocationRelativeTo(null);
        Jdialog_InsertUpdate.pack();
        loadDrugs();

    }//GEN-LAST:event_btnInsertActionPerformed

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        flag = "update";

        if (tableOrderList.getSelectedRowCount() == 1) {

            Jdialog_Update.setVisible(true);
            Jdialog_Update.pack();
            Jdialog_Update.setLocationRelativeTo(null);
            DefaultTableModel myModel = (DefaultTableModel) tableOrderList.getModel();

            try {
                int orderID = Integer.parseInt((String) myModel.getValueAt(tableOrderList.getSelectedRow(), 0));
                txtOrderID.setText(Integer.toString(orderID));
                loadDrugs(orderID);
                String str = String.valueOf(myModel.getValueAt(tableOrderList.getSelectedRow(), 0));
                System.out.println(str);
                Orders orders = new Orders();
                orders.setOrderID(orderID);
                ResultSet resultSet = OrderManager.getCustomerinfo(orders);
                if (resultSet.next()) {
                    txtCustomerID1.setText(String.valueOf(resultSet.getInt(2)).trim());
                    txtCustomerName1.setText(resultSet.getString(3).trim());
                    txtEmail1.setText(resultSet.getString(4).trim());
                    txtAddress1.setText(resultSet.getString(5).trim());
                    txtPhone1.setText(resultSet.getString(6).trim());
                    txtTotal1.setText(String.valueOf(resultSet.getDouble(8)).trim());
                    if (resultSet.getBoolean(7) == true) {
                        txtRelationYesNo1.setText("Yes");
                        txtDiscount1.setText("Discounted");
                    } else {
                        txtRelationYesNo1.setText("No");
                        txtDiscount1.setText("");
                    }
                }

//                DefaultTableModel tableModel = (DefaultTableModel) jtbDrugs1.getModel();
//                tableModel.setRowCount(0);
//                ResultSet resultSet2 = OrderManager.getDrugOrderDetail(orderID);
//                while (resultSet2.next()) {
//                    Vector vector = new Vector();
//
//                    vector.add(resultSet2.getString(2).trim());
//                    vector.add(resultSet2.getString(3).trim());
//                    vector.add(String.valueOf(resultSet2.getDouble(4)).trim());
//                    vector.add(String.valueOf(resultSet2.getInt(5)).trim());
//
//                    double ttp = resultSet2.getDouble(4) * resultSet2.getInt(5);
//
//                    vector.add(String.valueOf(ttp));
//                    tableModel.addRow(vector);
//                }
            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            }

        } else {
            JOptionPane.showMessageDialog(this, "Please choose an order to update!", "Message", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_btnUpdateActionPerformed

    private void btnChooseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChooseActionPerformed
        //load selected customer into form
        if (tbCustomerList.getSelectedRowCount() == 1) {
            int selectedRow = tbCustomerList.getSelectedRow();
            selectedRow = tbCustomerList.convertRowIndexToModel(selectedRow);
            txtCustomerID.setText((String) tbCustomerList.getValueAt(selectedRow, 0));
            txtCustomerName.setText((String) tbCustomerList.getValueAt(selectedRow, 1));
            txtEmail.setText((String) tbCustomerList.getValueAt(selectedRow, 3));
            txtAddress.setText((String) tbCustomerList.getValueAt(selectedRow, 4));
            txtPhone.setText((String) tbCustomerList.getValueAt(selectedRow, 2));
            txtRelationYesNo.setText((String) tbCustomerList.getValueAt(selectedRow, 5));
            JDialog_ChooseCustomer.dispose();
            DefaultTableModel tableModel = (DefaultTableModel) jtbDrugs.getModel();
            double sum = 0;
            int col = 4;
            for (int i = 0; i < tableModel.getRowCount(); i++) {
                sum += Double.parseDouble((String) tableModel.getValueAt(i, col));

            }
            if (txtRelationYesNo.getText().equals("No")) {
                txtTotal.setText(Double.toString(sum));
                txtDiscount.setText("");
            } else if (txtRelationYesNo.getText().equals("Yes")) {
                sum = sum - (sum * 0.1);
                txtTotal.setText(Double.toString(sum));
                txtDiscount.setText("Discounted");
            } else {
                txtTotal.setText(Double.toString(sum));
                txtDiscount.setText("");
            }
        }
    }//GEN-LAST:event_btnChooseActionPerformed

    private void btnChooseCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChooseCustomerActionPerformed

        loadCustomer();
        JDialog_ChooseCustomer.setVisible(true);
        JDialog_ChooseCustomer.pack();

    }//GEN-LAST:event_btnChooseCustomerActionPerformed

    private void btnAddtoOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddtoOrderActionPerformed

        if (txtQuantity.getText().equals("")) {
            JOptionPane.showMessageDialog(Jdialog_InsertUpdate, "Drug quantity is empty!!");
            txtQuantity.requestFocus();
        } else if (!txtQuantity.getText().matches("-?\\d+") || Integer.parseInt(txtQuantity.getText()) <= 0) {
            JOptionPane.showMessageDialog(Jdialog_InsertUpdate, "Drug quantity must be an integer number and greater than zero!!");
            txtQuantity.requestFocus();
        } else {
            //Add Drug from drug list to order's drugs list
            if (jtbDrugslist.getSelectedRowCount() == 1) {

                DefaultTableModel tableModel = (DefaultTableModel) jtbDrugs.getModel();

                int selectedRow = jtbDrugslist.getSelectedRow();
                selectedRow = jtbDrugslist.convertRowIndexToModel(selectedRow);
                if (tableModel.getRowCount() > 0) {
                    //if table Drug is not null
                    for (int i = 0; i < tableModel.getRowCount(); i++) {//loop to get value of all row from table
                        if (jtbDrugslist.getValueAt(selectedRow, 0).equals(jtbDrugs.getValueAt(i, 0))) {
                            //if  Drug user want to add is already choosed

                            int quandr = Integer.parseInt((String) jtbDrugs.getValueAt(i, 3));
                            int quan = Integer.parseInt(txtQuantity.getText());
                            double unitp = Double.parseDouble((String) jtbDrugs.getValueAt(i, 2));
                            //update quantity and total price of each drugID   
                            jtbDrugs.setValueAt(Integer.toString(quandr + quan), i, 3);
                            jtbDrugs.setValueAt(Double.toString((quandr + quan) * unitp), i, 4);
                        } else { //else if table is null, add the drug what user choose to to ordered drug list
                            Vector vector = new Vector();
                            vector.add((String) jtbDrugslist.getValueAt(selectedRow, 0));//drug ID
                            vector.add((String) jtbDrugslist.getValueAt(selectedRow, 1));//drug name
                            vector.add((String) jtbDrugslist.getValueAt(selectedRow, 3));//unit price
                            vector.add((String) txtQuantity.getText());//quantity

                            int quan = Integer.parseInt(txtQuantity.getText());
                            double uniprice = Double.parseDouble((String) jtbDrugslist.getValueAt(selectedRow, 3));
                            double tp = quan * uniprice;

                            vector.add(Double.toString(tp));//totalprice 
                            tableModel.addRow(vector);
                            break;
                        }
                    }
                } else {
                    Vector vector = new Vector();
                    vector.add((String) jtbDrugslist.getValueAt(selectedRow, 0));//drug ID
                    vector.add((String) jtbDrugslist.getValueAt(selectedRow, 1));//drug name
                    vector.add((String) jtbDrugslist.getValueAt(selectedRow, 3));//unit price
                    vector.add((String) txtQuantity.getText());//quantity

                    int quan = Integer.parseInt(txtQuantity.getText());
                    double uniprice = Double.parseDouble((String) jtbDrugslist.getValueAt(selectedRow, 3));
                    double tp = quan * uniprice;

                    vector.add(Double.toString(tp));//totalprice 
                    tableModel.addRow(vector);
                }

            } else {
                JOptionPane.showMessageDialog(Jdialog_InsertUpdate, "Please choose a drug!");
                jtbDrugslist.requestFocus();
            }
            //Order total price calculate
            DefaultTableModel tableModel = (DefaultTableModel) jtbDrugs.getModel();
            double sum = 0;
            int col = 4;
            for (int i = 0; i < tableModel.getRowCount(); i++) {
                sum += Double.parseDouble((String) tableModel.getValueAt(i, col));

            }
            if (txtRelationYesNo.getText().equals("No")) {
                txtTotal.setText(Double.toString(sum));
            } else {
                sum = sum - (sum * 0.1);
                txtTotal.setText(Double.toString(sum));
                txtDiscount.setText("Discounted");
            }

        }
    }//GEN-LAST:event_btnAddtoOrderActionPerformed

    private void txtQuantityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtQuantityActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtQuantityActionPerformed

    private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed
        //remove Drugs from order
        if (jtbDrugs.getSelectedRowCount() == 1) {
            DefaultTableModel tableModel = (DefaultTableModel) jtbDrugs.getModel();

            int selectedRow = jtbDrugs.getSelectedRow();
            selectedRow = jtbDrugs.convertRowIndexToModel(selectedRow);
            tableModel.removeRow(selectedRow);

            //DefaultTableModel tableModel = (DefaultTableModel) jtbDrugs.getModel();
            double sum = 0;
            int col = 4;
            for (int i = 0; i < tableModel.getRowCount(); i++) {
                sum += Double.parseDouble((String) tableModel.getValueAt(i, col));

            }
            if (txtRelationYesNo.getText().equals("No")) {
                txtTotal.setText(Double.toString(sum));
            } else {
                sum = sum - (sum * 0.1);
                txtTotal.setText(Double.toString(sum));
                txtDiscount.setText("Discounted");
            }

        }
    }//GEN-LAST:event_btnRemoveActionPerformed

    private void btnSaveOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveOrderActionPerformed
        // Convert to timestamp
        //Calendar calendar = new GregorianCalendar();
        Calendar cal = Calendar.getInstance();
        Timestamp orderDate = new Timestamp(cal.getTimeInMillis());
        //Timestamp shippeđate = new Timestamp(cal.getTimeInMillis());

        Calendar calendar = new GregorianCalendar();
        calendar.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH) + 50);
        Timestamp shippedDate = new Timestamp(calendar.getTimeInMillis());
        DefaultTableModel myModel = (DefaultTableModel) jtbDrugs.getModel();
        if (!txtCustomerID.getText().equals("")
                && !txtTotal.getText().equals("")
                && myModel.getRowCount() > 0) {

            //get data
            Orders order = new Orders();
            order.setCustomerID(Integer.parseInt(txtCustomerID.getText().trim()));
            order.setOrderDate(orderDate);
            order.setShippedDate(shippedDate);
            order.setSubTotal(Double.parseDouble(txtTotal.getText().trim()));
            order.setStatus("UNCOMPLETED");

            //get order detail data
            DefaultTableModel tableModel = (DefaultTableModel) jtbDrugs.getModel();
            for (int i = 0; i < tableModel.getRowCount(); i++) {
                try {
                    order.setDrugID(Integer.parseInt((String) tableModel.getValueAt(i, 0)));//tableModel.getValueAt(i,0 );
                    order.setUnitPrice(Double.parseDouble((String) tableModel.getValueAt(i, 2)));
                    order.setQuantity(Integer.parseInt((String) tableModel.getValueAt(i, 3)));
                    order.setDiscount(0.5);
                    OrderManager.insertOrderDetail(order, OrderManager.getOrderID().getInt(1));
//                OrderManager.insertNew(order);/
                } catch (SQLException ex) {
                    Logger.getLogger(OrdersList.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            try {

                if (OrderManager.insert(order)) {
                    JOptionPane.showMessageDialog(null, "Add new order successfully !", "Add new Customer", JOptionPane.INFORMATION_MESSAGE);
                    loadOrder();

                } else {
                    JOptionPane.showMessageDialog(null, "Add new order error", "Add new Customer", JOptionPane.ERROR_MESSAGE);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please fill information", "Message", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnSaveOrderActionPerformed

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
        Jdialog_InsertUpdate.dispose();
    }//GEN-LAST:event_btnExitActionPerformed

    private void txtQuantity1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtQuantity1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtQuantity1ActionPerformed

    private void btnRemovedrugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemovedrugActionPerformed
        if (jtbDrugs1.getSelectedRowCount() == 1) {
            int reply = JOptionPane.showConfirmDialog(null, "Do you want to delete this drug?",
                    "Message", JOptionPane.YES_NO_OPTION);
//            if (reply == JOptionPane.YES_OPTION) {
            try {
                DefaultTableModel myModel = (DefaultTableModel) jtbDrugs1.getModel();
                if (myModel.getRowCount() != 1) {
                    int orderID = Integer.parseInt(txtOrderID.getText());
                    int drugID = Integer.parseInt((String) myModel.getValueAt(jtbDrugs1.getSelectedRow(), 0));
                    System.out.println(orderID + "" + drugID);
                    Orders orders = new Orders();
                    orders.setOrderID(orderID);
                    orders.setDrugID(drugID);
                    int myRS = OrderManager.selectByOrderIDDrugID(orders);
                    if (myRS == 1) {
                        loadDrugs(orderID);
                    }
                    //loadData();
                    loadDrugs();
                } else {
                    JOptionPane.showMessageDialog(null, "Cannot delete drug list \nhas olny 1 record", "Message", JOptionPane.ERROR_MESSAGE);
                }
            } catch (SQLException ex) {
                System.out.println(ex.toString());
            }
        }
//        } else {
//            JOptionPane.showMessageDialog(null, "Please choose a drug", "Message", JOptionPane.ERROR_MESSAGE);
//        }
    }//GEN-LAST:event_btnRemovedrugActionPerformed

    private void jtbDrugs1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbDrugs1MouseClicked
        if (jtbDrugs1.getSelectedRowCount() == 1) {
            tableModel = (DefaultTableModel) jtbDrugs1.getModel();
            txtQuantity1.setText((String) tableModel.getValueAt(jtbDrugs1.getSelectedRow(), 3));

        }
    }//GEN-LAST:event_jtbDrugs1MouseClicked

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void btnSaveUpdateOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveUpdateOrderActionPerformed
        if (jtbDrugs1.getSelectedRowCount() == 1) {
            //get value from txtQuantity1
            int quantity = 0;
            int orderID = 0;
            int drugID = 0;
            double subtotal = 0.0;
            boolean result;
            String status = "";
            jtbDrugs1.setFocusable(true);
            DefaultTableModel myModel = (DefaultTableModel) jtbDrugs1.getModel();

            if (jtbDrugs1.getSelectedRowCount() == 1) {

                try {

                    quantity = Integer.parseInt(txtQuantity1.getText());
                    orderID = Integer.parseInt(txtOrderID.getText());
                    drugID = Integer.valueOf(String.valueOf(myModel.getValueAt(jtbDrugs1.getSelectedRow(), 0)));
                    subtotal = Double.parseDouble(txtTotal1.getText());
                    status = String.valueOf(cbRole.getSelectedItem());
                    // Execute update query
//                    String.valueOf(cbRole.getSelectedItem())
                    ResultSet rs = OrderManager.selectStockAvailable(drugID);
                    if (rs.next()) {
                        if (rs.getInt(1) > quantity) {
                            result = OrderManager.updateOrderByID(quantity, orderID, drugID, subtotal, status);
                            if (result) {
                                loadDrugs(orderID);
                                loadOrder();
                                // update vao bang Drugs
                                if (status.equals("COMPLETED")) {
                                    boolean result2 = OrderManager.updateStock(quantity, drugID);
                                    if (!result2) {
                                        JOptionPane.showMessageDialog(null, "Error during update", "Message", JOptionPane.ERROR_MESSAGE);
                                    }
                                }
                            } else {
                                JOptionPane.showMessageDialog(null, "Update failed", "Message", JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "Quantity must be less than stock", "Message", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(OrdersList.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please choose a drug", "Message", JOptionPane.ERROR_MESSAGE);

        }
    }//GEN-LAST:event_btnSaveUpdateOrderActionPerformed

    private void btnSaveQuantityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveQuantityActionPerformed
        if (jtbDrugs1.getSelectedRowCount() == 1) {
            if (txtQuantity1.getText().matches("^[0-9]{1,8}")) {
                DefaultTableModel myModel = (DefaultTableModel) jtbDrugs1.getModel();
                myModel.setValueAt(txtQuantity1.getText().trim(), jtbDrugs1.getSelectedRow(), 3);
                double totalPrice = Double.parseDouble(String.valueOf(myModel.getValueAt(jtbDrugs1.getSelectedRow(), 2)))
                        * Double.parseDouble(String.valueOf(myModel.getValueAt(jtbDrugs1.getSelectedRow(), 3)));
                myModel.setValueAt(String.valueOf(totalPrice), jtbDrugs1.getSelectedRow(), 4);
                double subTotal = 0.0;
                for (int i = 0; i < myModel.getRowCount(); i++) {
                    subTotal += Double.parseDouble(String.valueOf(myModel.getValueAt(i, 4)));
                }
                txtTotal1.setText(String.valueOf(subTotal));
            } else {
                JOptionPane.showMessageDialog(this, "Quantity mus be number", "Message", JOptionPane.ERROR_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(this, "Please a drug", "Message", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnSaveQuantityActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(OrdersList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(OrdersList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(OrdersList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(OrdersList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new OrdersList().setVisible(true);
            }
        });
    }
//load customer from database to table

    private void loadCustomer() {
        DefaultTableModel tableModel = (DefaultTableModel) tbCustomerList.getModel();
        tableModel.setRowCount(0);
        try {

            // Fill all record from users table
            ResultSet resultSet = CustomerManager.displayAllRows();
            while (resultSet.next()) {
                Vector vector = new Vector();
                vector.add(resultSet.getString(1).trim());//ID
                vector.add(resultSet.getString(2).trim());//name
                vector.add(resultSet.getString(5).trim());//phone
                vector.add(resultSet.getString(3).trim());//email
                vector.add(resultSet.getString(4).trim());//address
                //relation
                if (resultSet.getBoolean(6) == true) {
                    vector.add("Yes");
                } else {
                    vector.add("No");
                }
                tableModel.addRow(vector);
            }
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }

    private void loadOrder() {
        tableModel = (DefaultTableModel) tableOrderList.getModel();
        tableModel.setRowCount(0);
        try {

            // Add to table OrderList
            ResultSet resultSet = OrderManager.displayOrder();
            while (resultSet.next()) {
                Vector vector = new Vector();
                vector.add(String.valueOf(resultSet.getInt(1)).trim());//OrderID
                vector.add(String.valueOf(resultSet.getString(2)).trim());//Customer
                vector.add(String.valueOf(resultSet.getTimestamp(3)).trim());//Orderdate
                vector.add(String.valueOf(resultSet.getTimestamp(4)).trim());//sgipdate
                vector.add(String.valueOf(resultSet.getDouble(5)).trim());//total
                vector.add(resultSet.getString(6).trim());//stt
                tableModel.addRow(vector);
            }
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }

    //load Drug from data base to table
    private void loadDrugs() {
        DefaultTableModel tableModel = (DefaultTableModel) jtbDrugslist.getModel();
        tableModel.setRowCount(0);
        try {

            // Fill all record from users table
            ResultSet resultSet = DrugManager.displayAllRows();
            while (resultSet.next()) {
                Vector vector = new Vector();
                vector.add(String.valueOf(resultSet.getInt(1)).trim());//DrugID
                vector.add(resultSet.getString(3).trim());//name of Drug
                vector.add(resultSet.getString(4).trim());//unit
                vector.add(resultSet.getString(5).trim());//unit price
                vector.add(String.valueOf(resultSet.getInt(6)).trim());//stock
                vector.add(resultSet.getString(7).trim());//description
                tableModel.addRow(vector);

            }

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }

    private void loadDrugs(int id) {
        DefaultTableModel tableModel = (DefaultTableModel) jtbDrugs1.getModel();
        tableModel.setRowCount(0);
        try {

            // Fill all record from users table
            ResultSet resultSet = OrderManager.getDrugOrderDetail(id);
            while (resultSet.next()) {
                Vector vector = new Vector();

                vector.add(resultSet.getString(2).trim());
                vector.add(resultSet.getString(3).trim());
                vector.add(String.valueOf(resultSet.getDouble(4)).trim());
                vector.add(String.valueOf(resultSet.getInt(5)).trim());

                double ttp = resultSet.getDouble(4) * resultSet.getInt(5);

                vector.add(String.valueOf(ttp));
                tableModel.addRow(vector);

            }

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog JDialog_ChooseCustomer;
    private javax.swing.JDialog Jdialog_InsertUpdate;
    private javax.swing.JDialog Jdialog_Update;
    private javax.swing.JButton btnAddtoOrder;
    private javax.swing.JButton btnChoose;
    private javax.swing.JButton btnChooseCustomer;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnInsert;
    private javax.swing.JButton btnRemove;
    private javax.swing.JButton btnRemovedrug;
    private javax.swing.JButton btnSaveOrder;
    private javax.swing.JButton btnSaveQuantity;
    private javax.swing.JButton btnSaveUpdateOrder;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JComboBox cbRole;
    private javax.swing.JButton jButton4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JLabel jlblAccList_Email1;
    private javax.swing.JTable jtbDrugs;
    private javax.swing.JTable jtbDrugs1;
    private javax.swing.JTable jtbDrugslist;
    private javax.swing.JLabel lbAddress;
    private javax.swing.JLabel lbAddress1;
    private javax.swing.JLabel lbCustomerID;
    private javax.swing.JLabel lbCustomerID1;
    private javax.swing.JLabel lbCustomerName;
    private javax.swing.JLabel lbCustomerName1;
    private javax.swing.JLabel lbEmail;
    private javax.swing.JLabel lbEmail1;
    private javax.swing.JLabel lbOrderID;
    private javax.swing.JLabel lbOrderManager;
    private javax.swing.JLabel lbPhone;
    private javax.swing.JLabel lbPhone1;
    private javax.swing.JLabel lbQuantity;
    private javax.swing.JLabel lbQuantity1;
    private javax.swing.JLabel lbRelation;
    private javax.swing.JLabel lbRelation1;
    private javax.swing.JLabel lbTotal;
    private javax.swing.JLabel lbTotal1;
    private javax.swing.JPanel pbDrugsList;
    private javax.swing.JPanel pnCustomerInfo;
    private javax.swing.JPanel pnCustomerInfo1;
    private javax.swing.JPanel pnDrugs;
    private javax.swing.JPanel pnDrugs1;
    private javax.swing.JTable tableOrderList;
    private javax.swing.JTable tbCustomerList;
    private javax.swing.JLabel txtAddress;
    private javax.swing.JLabel txtAddress1;
    private javax.swing.JLabel txtCustomerID;
    private javax.swing.JLabel txtCustomerID1;
    private javax.swing.JLabel txtCustomerName;
    private javax.swing.JLabel txtCustomerName1;
    private javax.swing.JLabel txtDiscount;
    private javax.swing.JLabel txtDiscount1;
    private javax.swing.JLabel txtEmail;
    private javax.swing.JLabel txtEmail1;
    private javax.swing.JLabel txtOrderID;
    private javax.swing.JLabel txtPhone;
    private javax.swing.JLabel txtPhone1;
    private javax.swing.JTextField txtQuantity;
    private javax.swing.JTextField txtQuantity1;
    private javax.swing.JLabel txtRelationYesNo;
    private javax.swing.JLabel txtRelationYesNo1;
    private javax.swing.JLabel txtTotal;
    private javax.swing.JLabel txtTotal1;
    // End of variables declaration//GEN-END:variables
String flag = "";
}
